<template>
    <div v-if="detailStatus" class="m-edit-modal">
        <div class="header">
            {{title}}
            <span @click="close"><Icon type="close-round"></Icon></span>
        </div>
        <div class="m-content">

            <Form ref="myData" :model="detailData" :rules="ruleValidate" :label-width="100" style="width: 900px"
                  :inline="true">

                <Row>
                    <FormItem label="维度名称" prop="dimension_name">
                        <Input type="text" placeholder="请输入..." v-model="myData.dimension_name" style="width: 200px"/>
                    </FormItem>
                </Row>
                <Row>
                    <FormItem label="维度标志" prop="dimension_flag" >
                        <Input  :disabled="disabledFlag"  type="text" placeholder="请输入..." v-model="myData.dimension_flag" style="width: 200px"/>
                    </FormItem>
                </Row>
                <Row>
                    <FormItem label="指标维度" prop="dimension_target">
                        <Select v-model="myData.dimension_target"  style="width: 100px">
                            <Option value="+">+</Option>
                            <Option value="-">-</Option>
                        </Select>
                        <Input type="number" placeholder="请输入..." v-model="myData.norm" style="width: 100px"/>
                        <Select  placeholder="请选择单位" style="width: 100px" v-model="myData.unitName">
                            <Option value="万">万</Option>
                            <Option value="次">次</Option>
                            <Option value="%">%</Option>
                        </Select>
                    </FormItem>
                </Row>
                <Row>
                    <FormItem label="评分维度">
                        <Select v-model="myData.dimension_score" style="width: 100px">
                            <Option value="+">+</Option>
                            <Option value="-">-</Option>
                        </Select>
                        <Input type="number"  placeholder="请输入..." v-model="myData.score" style="width: 100px"/>
                        分
                    </FormItem>
                </Row>



                <FormItem>
                    <Button type="primary" @click="handleSubmit('myData')">提交</Button>
                </FormItem>
            </Form>
        </div>
    </div>
</template>
<script>

    import API from '../../config/api'
    import qs from 'qs'
    import {formatDateTime, checkTel} from '../../config/utils'

    import UE from '../../components/ue/ue.vue';

    export default {
        props: ['detailStatus', 'detailData', 'title','testPar'],
        watch: {
            testPar(val) {
                if(val.indexOf("add")<0){
                    this.disabledFlag=true;
                }else{
                    this.disabledFlag=false;
                }

            }
        },
        data() {
            return {
                disabledFlag:false,
                dealerstop: 1,
                ruleValidate: {
                    dimension_name:[
                        {required:true,message: '维度名称不能为空', trigger: 'blur'}
                    ],
                    dimension_flag: [
                        {required: true, message: '维度标志不能为空', trigger: 'blur'}
                    ],
                },
                visible: true,
                defaultMsg: '',

            }
        },
        methods: {
            saveContentInfo() {
                let vm = this ;
                //查询所有数据
                let  params = qs.stringify( this.myData);
                this.axios.post(process.env.API_CAR+"/score_dimension/save?"+ params).then(response=>{
                    if (response.data.code === '1') {
                        this.close();
                        vm.$Message.success(response.data.result)

                    } else {
                        vm.$Message.error(response.data.info);
                    }
                }, error=>{

                });

            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let vm = this;
                        if(vm.myData.dimension_target==undefined||vm.myData.dimension_target==''){
                            this.$Message.error('指标维度为空!');
                        }
                       else if(vm.myData.norm==undefined||vm.myData.norm==''){
                            this.$Message.error('指标为空!');
                        }
                        else if(vm.myData.dimension_score==undefined||vm.myData.dimension_score==''){
                            this.$Message.error('评分维度为空!');
                        }
                        else if(vm.myData.unitName==undefined||vm.myData.unitName==''){
                            this.$Message.error('单位名称为空!');
                        }
                        else if(vm.myData.score==undefined||vm.myData.score==''){
                            this.$Message.error('指标分数为空!');
                        }
                       else{
                            this.saveContentInfo();
                        }

                    } else {
                        this.$Message.error('请完善信息!');
                    }
                })
            },
            close() {
                this.defaultMsg = "";
                this.$emit('closeModal')
            },
        },
        computed: {
            myData() {
           /*    let vm = this;
                if (vm.editData.id) {
                    vm.editData.releaseTime = formatDateTime(vm.editData.releaseTime);
                    vm.defaultMsg = vm.editData.infoContent;
                }*/

/*         */
                return this.detailData;
            }
        },
        created() {
            this.defaultMsg = "";
        }
    }
</script>
<style lang='scss' scoped>
    .m-edit-modal {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background-color: #fff;
        z-index: 100;

        .header {
            background-color: #f8f8f9;
            height: 45px;
            line-height: 45px;
            font-size: 16px;
            padding-left: 25px;
            padding-right: 5px;
            color: #000;
            box-shadow: 1px 1px 1px rgba(220, 172, 172, .5);

            span {
                float: right;
                padding: 0 20px;
                cursor: pointer;
            }

        }
        .m-content {
            margin-top: 20px;
            padding-bottom: 100px;
            overflow-y: auto;
        }

        .list-header {
            height: 45px;
            color: #333;
            line-height: 45px;
        }

        .list-row {
            padding-left: 100px;
            font-size: 14px;
            line-height: 40px;
        }

    }
</style>
